#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0;bool f=0;char ch=getchar();
	while(ch<'0'||ch>'9')f^=(ch=='-'),ch=getchar();
	while('0'<=ch&&ch<='9')x=(x<<1)+(x<<3)+(ch^48),ch=getchar();
	return f?-x:x;
}
const int Maxn=5e4+5,B=365;
int head[Maxn],to[Maxn],nxt[Maxn],cnt1;
inline void add1(int u,int v){
	to[++cnt1]=v;nxt[cnt1]=head[u];
	head[u]=cnt1;
}
int n,q;
int pr[Maxn];
int id[Maxn];
int f[Maxn],dfn[Maxn],cnt,top[Maxn],si[Maxn],son[Maxn],dep[Maxn];
void dfs(int u){
	dfn[u]=++cnt;id[cnt]=u;
	si[u]=1;dep[u]=dep[f[u]]+1;
	for(int i=head[u];i;i=nxt[i]){
		int y=to[i];
		dfs(y);
		si[u]+=si[y];
		if(si[son[u]]<si[y])son[u]=y;
	}
}
void dfs2(int u,int t){
	top[u]=t;
	if(!son[u])return;
	dfs2(son[u],t);
	for(int i=head[u];i;i=nxt[i]){
		int y=to[i];
		if(y==son[u])continue;
		dfs2(y,y);
	}
}
inline int lca(int u,int v){
	while(top[u]^top[v]){
		if(dep[top[u]]<dep[top[v]])swap(u,v);
		u=f[top[u]];
	}return dep[u]<dep[v]?u:v;
}
struct Query{int l,r,id;}Q[Maxn];
int belong[Maxn];
inline bool cmp(Query a,Query b){return belong[a.l]==belong[b.l]?a.r<b.r:belong[a.l]<belong[b.l];}
multiset<int>s;
int ans=0,vis[Maxn];
int a[Maxn];
inline void add(int x){
	x=a[x];
	if(!vis[x])ans++;//,printf("f%d\n",x);
	vis[x]++;
	x=dfn[x];
	auto it=prev(s.lower_bound(x));
	int l=*it;
	it=s.lower_bound(x+1);
	int r=*it;
	s.insert(x);
	int Lca=0;
	if(l>0){
		Lca=lca(id[l],id[x]);
		if(!vis[Lca])ans++;//,printf("%d\n",Lca);
		vis[Lca]++;
	}
	if(r<=n){
		Lca=lca(id[r],id[x]);
		if(!vis[Lca])ans++;//,printf("%d\n",Lca);
		vis[Lca]++;
	}
	if(l>0&&r<=n){
		Lca=lca(id[l],id[r]);
		if(vis[Lca]==1)ans--;//,printf("ss%d\n",Lca);
		vis[Lca]--;
	}
}
inline void del(int x){
	x=a[x];
	if(vis[x]==1)ans--;//,printf("fss%d\n",x);
	vis[x]--;
	x=dfn[x];
	auto it=prev(s.lower_bound(x));
	int l=*it;
	it=s.lower_bound(x+1);
	int r=*it;
	s.erase(s.find(x));
	int Lca=0;
	if(l>0){
		Lca=lca(id[l],id[x]);
		if(vis[Lca]==1)ans--;//,printf("ss%d\n",Lca);
		vis[Lca]--;
	}
	if(r<=n){
		Lca=lca(id[r],id[x]);
		if(vis[Lca]==1)ans--;//,printf("ss%d\n",Lca);
		vis[Lca]--;
	}
	if(l>0&&r<=n){
		Lca=lca(id[l],id[r]);
		if(!vis[Lca])ans++;//,printf("%d\n",Lca);
		vis[Lca]++;
	}
}
int main(){
	freopen("escape.in","r",stdin);
	freopen("escape.out","w",stdout);
	n=read();q=read();
	for(int i=1;i<=n;i++)belong[i]=i/B;
	for(int i=2;i<=n;i++)f[i]=read(),add1(f[i],i);
	for(int i=1;i<=n;i++)a[i]=read();
	dfs(1);dfs2(1,1);
	for(int i=1;i<=q;i++)Q[i]={read(),read(),i};
	sort(Q+1,Q+1+q,cmp);
	int l=1,r=0;s.insert(0);s.insert(n+1);
	for(int i=1;i<=q;i++){
//		printf("%d %d %d %d\n",l,r,Q[i].l,Q[i].r);
		while(r<Q[i].r)add(++r);
		while(r>Q[i].r)del(r--);
		while(l>Q[i].l)add(--l);
		while(l<Q[i].l)del(l++);
		pr[Q[i].id]=ans;
	}
	for(int i=1;i<=q;i++)printf("%d\n",pr[i]);
	return 0;
}
/*
5 2
1 1 3 3
1 2 3 4 5
3 5
2 4
*/
